<%@page import="com.liferay.portal.kernel.util.Validator"%>
<%@page import="javax.portlet.PortletURL"%>
<%@page import="java.util.List"%>
<%@page import="com.myBook.slayer.model.MyBook"%>
<%@page import="com.myBook.slayer.model.impl.MyBookImpl"%>
<%@page import="com.myBook.slayer.service.MyBookLocalServiceUtil"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="portlet" uri="http://java.sun.com/portlet" %>

<portlet:defineObjects/>

<h1>List of Books</h1>
 
 <%
 	List<MyBook> books = (List<MyBook>) request.getAttribute("SEARCH_RESULT");
 
 if (Validator.isNull(books)) {
    int count = MyBookLocalServiceUtil.getMyBooksCount();
    books = MyBookLocalServiceUtil.getMyBooks(0, count);
 }
   
    PortletURL editURL=renderResponse.createRenderURL();
    editURL.setParameter("action", "showUpdateForm");
    
    PortletURL deleteBookURL = renderResponse.createActionURL();
	deleteBookURL.setParameter("action", "deleteBook");
	
%>
 <table border="1" width="80%">
 <tr>
        
        <th>Book Title</th>
        <th>Author</th>
        <th>Edit</th>
        <th>Delete</th>
    </tr>
 <%
 for (MyBook book : books) {
 %>
    <tr>
        
        <td><%= book.getBookTitle() %></td>
        <td><%= book.getAuthor() %></td>
        
        <td>
        <%
            editURL.setParameter("id",String.valueOf(book.getBookId()));
        %>
            <a href="<%=editURL%>">Edit</a>
        </td>
        <td>
       		<% deleteBookURL.setParameter("id", String.valueOf(book.getBookId())); %>
       		<a href="<%= deleteBookURL.toString() %>">Delete &raquo;</a>
        </td>
    </tr>
    <%
 }
    %></br></br></br></br>
    <tr colspan = "4" align="center"><td><input type="button" value="Back" onclick="javascript:history.back()"/></td></tr>
</table>